<?php
/**
 * @package LaravelBoot
 *
 * @internal
 *
 * @author mawenpei
 * @date 2019/3/25 19:21
 * @version
 */
namespace App\Console\Commands;

use App\Models\Pay;
use App\Models\RechargeOrder;
use Carbon\Carbon;
use Illuminate\Console\Command;

class HandlePayCommand extends Command
{
    protected $signature = 'handle:pay {--id=}';

    protected $description = 'Handle Pay';

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $id = $this->option('id');
        if($id){
            $order = (new RechargeOrder())->query()->where('id',$id)->first();
            if(!$order){
                return $this->line('订单不存在');
            }
            $pay_id = $order->pay_id;
            $pay = Pay::query()->where('id',$pay_id)->first();
            if(!$pay) return $this->line('支付单不存在');
            if(!$pay->is_paid){
                $paySN = $pay->pay_sn;
                if(Pay::isYouKaOrder($paySN)){
                    Pay::setPaid($pay);
                }
                if(Pay::isHuaFeiOrder($paySN)){
                    Pay::setPaid_two($pay);
                }
                $this->line('手动支付成功');
            }else{
                $this->line('订单已支付');
            }

        }else{
            $this->line('id is not empty');
        }
    }

}